package hu.kisszoltan.boxescape.gui;

import hu.kisszoltan.boxescape.Game;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Polygon;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;


public class Player extends GameObject implements MouseMotionListener {

	private static final long serialVersionUID = 1L;

	private int size = 20;

	private Polygon me;

	public Player(GamePane gamePane) {
		super(gamePane);
		setColor(Color.RED);
		int sizeX = Math.round(size * gamePane.getScaleX());
		int sizeY = Math.round(size * gamePane.getScaleY());

		me = new Polygon(new int[] { 0, sizeX, sizeX, 0 }, new int[] { 0, 0,
				sizeY, sizeY }, 4);
	}

	public void moveTo(int x, int y) {
		int sizeX = Math.round(size * parent.getScaleX());
		int sizeY = Math.round(size * parent.getScaleY());

		x = x - sizeX / 2;
		y = y - sizeY / 2;

		me = new Polygon(new int[] { x, x + sizeX, x + sizeX, x }, new int[] {
				y, y, y + sizeY, y + sizeY }, 4);
	}

	@Override
	public void moveBy(float scaleX, float scaleY) {
//		moveTo(Math.round(me.xpoints[0] * scaleX), Math.round(me.ypoints[0]
//				* scaleY));
	}

	@Override
	public void paint(Graphics g) {
		g.setColor(getColor());
		g.fillPolygon(me);
	}

	@Override
	public void mouseDragged(MouseEvent e) {
		Game.getInstance().start();
		moveTo(e.getPoint().x, e.getPoint().y);
		parent.repaint();
	}

	@Override
	public void mouseMoved(MouseEvent e) {
	}

	@Override
	public Polygon getPolygon() {
		return me;
	}

	public boolean isPlayer() {
		return true;
	}

	@Override
	public void update() {
	}

}
